package spring;

import dao.UserDao;
import dao.UserDaoImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.testng.annotations.Test;

/**
 * Created by zhifu on 2015/3/26.
 */
public class XmlLoader {
    @Test
    public void testXmlBeanFactory(){
        Resource resource = new ClassPathResource("js-servlet.xml");
    }

    @Test
    public void testClasspathXmlApplicationContext(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("");
        UserDao userDao = (UserDaoImpl)applicationContext.getBean("UserDao");
    }

    @Test
    public void testFileSystemXmlApplicationContext(){
        String[] configs = {"",""};
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext(configs);
        UserDao userDao = (UserDaoImpl)applicationContext.getBean("UserDao");
    }

    @Test
    public void testXmlWebBeanFactory(){
//        ServletContext servletContext = request.getSession().getServletContext();
//        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    }
}
/*
* 注：web.xml里面可以定义两种参数：
        1、application范围内的参数，存放在servletcontext中。<context-param>中的参数（可以指定多个文件）
        2、servlet范围内的参数，只能在servlet的init()方法中取得， <init-param>中的参数，在init方法中用this.getInitParameter("param1")获取
* */
